package com.hnkywl.sts.action.cwgl.kmys;

import com.hnkywl.sts.entity.cwgl.kmys.Tyfzhsmc;
import com.hnkywl.sts.entity.cwgl.kmys.Tyfzhsys;
import com.hnkywl.sts.entity.sys.Gncz;
import com.hnkywl.sts.service.cwgl.kmys.TyfzhsmcService;
import com.hnkywl.sts.service.cwgl.kmys.TyfzhsysService;
import com.hnkywl.sts.service.organ.NbgsService;
import com.hnkywl.sts.service.sys.GnczService;
import com.hnkywl.sts.service.sys.YgService;
import jxl.Sheet;
import jxl.Workbook;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-5-11
 * Time: 下午2:23
 * To change this template use File | Settings | File Templates.
 */
@Namespace("/cwgl/kmys/tyfzhsys")
public class TyfzhsysAaction extends SimpleActionSupport {

    private TyfzhsysService tyfzhsysService;

    private TyfzhsmcService tyfzhsmcService;
    //角色名称
    private String mc;
    //分页组件 起始位置
    private int page;
    //分页组件 页面大小
    private int rows;
    //行索引
    private int index;
    //传入的角色实体
    private Tyfzhsys tyfzhsys;
    //传入的角色Id值
    private Long tyfzhsysId;
    //远程ajax验证的值
    private String validateVal;
    //需要远程ajax验证的属性
    private String validateField;

    private Long tyfzhsmcId;

    private boolean flag = true;

    private String code;

    private String tyMc;

    private String szIds;




    @Action("search_tyfzhsys")
    public String searchtyfzhsys() {
        return SUCCESS;
    }

    @Action("get_tyfzhsystreejson")
    public void getTyfzhsystreejson() {
        this.renderJson(this.tyfzhsysService.findAllTyfzhsysTree(tyfzhsmcId,flag));
    }

    @Actions({@Action("tyfzhsys_content")})
    public String fkshContent() {
        //进入update页面
        if (tyfzhsysId != null) {
            tyfzhsys = this.tyfzhsysService.findtyfzhsysDetail(tyfzhsysId);
        } else {
            tyfzhsys = new Tyfzhsys();
            tyfzhsys.setTyfzhsmc(tyfzhsmcService.findTyfzhsmcDetail(tyfzhsmcId));
        }
        return SUCCESS;
    }

    @Actions({@Action("tyfzhsys_sz")})
    public String tyfzhsysSz() {
        tyfzhsys = this.tyfzhsysService.findtyfzhsysDetail(tyfzhsysId);
        if(tyfzhsys.getTyfzhsmc().getDl().equals("xjllxm")){
            tyMc="现金流量项目";
        }else{
            tyMc=tyfzhsys.getMc();
        }
        return SUCCESS;
    }

    @Action("update_tyfzhsys")
    public void updatetyfzhsys() {
        try {
            this.tyfzhsysService.updatetyfzhsys(tyfzhsys);
            renderText("修改通用辅助核算映射成功!");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText(e.getMessage());
        }
    }

    @Action("add_tyfzhsys")
    public void addTyfzhsys() {
        try {
            this.tyfzhsysService.addtyfzhsys(tyfzhsys);
            renderText("新增通用辅助核算映射成功!");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText(e.getMessage());
        }
    }

    @Action("sz_tyfzhsys")
    public void szTyfzhsys() {
        try {
            this.tyfzhsysService.szTyfzhsys(tyfzhsysId,szIds);
            renderText("通用辅助核算设置成功!");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText(e.getMessage());
        }
    }


    @Action("delete_tyfzhsys")
    public void deleteTyfzhsys() {
        try {
            this.tyfzhsysService.deleteTyfzhsys(tyfzhsysId);
            renderText("{\"statusCode\":\"200\", \"message\":\"删除映射成功！\", \"operationType\":\"delete\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("tyfzhsysList")
    public void tyfzhsysList() {
        this.renderJson(this.tyfzhsysService.findAlltyfzhsys(tyfzhsmcId, mc, code, page, rows));
    }


    //=======================GetterAndSetter===========================================================


    public String getMc() {
        return mc;
    }

    public void setMc(String mc) {
        this.mc = mc;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public Tyfzhsys getTyfzhsys() {
        return tyfzhsys;
    }

    public void setTyfzhsys(Tyfzhsys tyfzhsys) {
        this.tyfzhsys = tyfzhsys;
    }

    public Long getTyfzhsysId() {
        return tyfzhsysId;
    }

    public void setTyfzhsysId(Long tyfzhsysId) {
        this.tyfzhsysId = tyfzhsysId;
    }

    public String getValidateVal() {
        return validateVal;
    }

    public void setValidateVal(String validateVal) {
        this.validateVal = validateVal;
    }

    public String getValidateField() {
        return validateField;
    }

    public void setValidateField(String validateField) {
        this.validateField = validateField;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Long getTyfzhsmcId() {
        return tyfzhsmcId;
    }

    public void setTyfzhsmcId(Long tyfzhsmcId) {
        this.tyfzhsmcId = tyfzhsmcId;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public String getTyMc() {
        return tyMc;
    }

    public void setTyMc(String tyMc) {
        this.tyMc = tyMc;
    }

    public String getSzIds() {
        return szIds;
    }

    public void setSzIds(String szIds) {
        this.szIds = szIds;
    }

    //========================Setter========================================
    @Autowired
    public void setTyfzhsysService(TyfzhsysService tyfzhsysService) {
        this.tyfzhsysService = tyfzhsysService;
    }

    @Autowired
    public void setTyfzhsmcService(TyfzhsmcService tyfzhsmcService) {
        this.tyfzhsmcService = tyfzhsmcService;
    }
}
